package com.songcha.sakura.download.base

import android.os.Parcel
import android.os.Parcelable
import com.songcha.sakura.download.base.DownloadTask
import com.songcha.sakura.download.IDownloadManager
import com.songcha.sakura.download.IDownloaderListener

class DownloadDelegate(val mDownloader: IDownloader) : IDownloader {

    constructor(parcel: Parcel) : this(
        parcel.readParcelable(IDownloader::class.java.classLoader)!!
    )


    override fun download(task: DownloadTask, listener: IDownloaderListener, iDownloadManager: IDownloadManager):Int {
        return mDownloader.download(task,listener,iDownloadManager)
    }

    override fun validateUrl(url: String): Boolean {
        return false
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        //super.writeToParcel(parcel, flags)
        parcel.writeParcelable(mDownloader, flags)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<DownloadDelegate> {
        override fun createFromParcel(parcel: Parcel): DownloadDelegate {
            return DownloadDelegate(parcel)
        }

        override fun newArray(size: Int): Array<DownloadDelegate?> {
            return arrayOfNulls(size)
        }
    }

}